package operation;

import JDBC.JDBCUtils;

import Medicine.Pharmacy;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;


import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

// 查找药品
public class FindEquipment implements IOPeration{
    @Override
    public void work(Pharmacy pharmacy) throws SQLException {
        //创建QueryRunner对象
        QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
        System.out.println("在药房内查找器械...");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要查找的器械名字");
        String name = sc.nextLine();

        String query = "SELECT * FROM Equipment";
        List<Map<String, Object>> equipmentList = qr.query(query, new MapListHandler());
        for (Map<String, Object> equipmentMap : equipmentList) {
            if (equipmentMap.get("name").equals(name)) {
                System.out.println("有您需要查找的器械");
                System.out.println(equipmentMap);
                return;
            }
        }
        System.out.println("没有您要找的器械");
    }
}
